home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / interp / perl5.005.tar.gz / perl5.005.tar / perl5.005 / t / op / my.t < prev    next >
Text File  |  1998-03-05  |  2KB  |  95 lines

  1. #!./perl
  2.  
  3. # $RCSfile: my.t,v $
  4.  
  5. print "1..30\n";
  6.  
  7. sub foo {
  8.     my($a, $b) = @_;
  9.     my $c;
  10.     my $d;
  11.     $c = "ok 3\n";
  12.     $d = "ok 4\n";
  13.     { my($a, undef, $c) = ("ok 9\n", "not ok 10\n", "ok 10\n");
  14.       ($x, $y) = ($a, $c); }
  15.     print $a, $b;
  16.     $c . $d;
  17. }
  18.  
  19. $a = "ok 5\n";
  20. $b = "ok 6\n";
  21. $c = "ok 7\n";
  22. $d = "ok 8\n";
  23.  
  24. print &foo("ok 1\n","ok 2\n");
  25.  
  26. print $a,$b,$c,$d,$x,$y;
  27.  
  28. # same thing, only with arrays and associative arrays
  29.  
  30. sub foo2 {
  31.     my($a, @b) = @_;
  32.     my(@c, %d);
  33.     @c = "ok 13\n";
  34.     $d{''} = "ok 14\n";
  35.     { my($a,@c) = ("ok 19\n", "ok 20\n"); ($x, $y) = ($a, @c); }
  36.     print $a, @b;
  37.     $c[0] . $d{''};
  38. }
  39.  
  40. $a = "ok 15\n";
  41. @b = "ok 16\n";
  42. @c = "ok 17\n";
  43. $d{''} = "ok 18\n";
  44.  
  45. print &foo2("ok 11\n","ok 12\n");
  46.  
  47. print $a,@b,@c,%d,$x,$y;
  48.  
  49. my $i = "outer";
  50.  
  51. if (my $i = "inner") {
  52.     print "not " if $i ne "inner";
  53. }
  54. print "ok 21\n";
  55.  
  56. if ((my $i = 1) == 0) {
  57.     print "not ";
  58. }
  59. else {
  60.     print "not" if $i != 1;
  61. }
  62. print "ok 22\n";
  63.  
  64. my $j = 5;
  65. while (my $i = --$j) {
  66.     print("not "), last unless $i > 0;
  67. }
  68. continue {
  69.     print("not "), last unless $i > 0;
  70. }
  71. print "ok 23\n";
  72.  
  73. $j = 5;
  74. for (my $i = 0; (my $k = $i) < $j; ++$i) {
  75.     print("not "), last unless $i >= 0 && $i < $j && $i == $k;
  76. }
  77. print "ok 24\n";
  78. print "not " if defined $k;
  79. print "ok 25\n";
  80.  
  81. foreach my $i (26, 27) {
  82.     print "ok $i\n";
  83. }
  84.  
  85. print "not " if $i ne "outer";
  86. print "ok 28\n";
  87.  
  88. # Ensure that C<my @y> (without parens) doesn't force scalar context.
  89. my @x;
  90. { @x = my @y }
  91. print +(@x ? "not " : ""), "ok 29\n";
  92. { @x = my %y }
  93. print +(@x ? "not " : ""), "ok 30\n";
  94.  
  95.